package com.neuedu.shixun.hospital2.controller;
import com.neuedu.shixun.hospital2.entity.JiBing;
import com.neuedu.shixun.hospital2.entity.JiBing2;
import com.neuedu.shixun.hospital2.entity.User;
import com.neuedu.shixun.hospital2.service.JiBingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/jiBing")
@CrossOrigin
public class JiBingController {
    @Autowired
    private JiBingService jiBingService;
    @GetMapping("getJiBing")
    public List<JiBing> getJiBing(){
        return jiBingService.getJiBing();
    }
    @GetMapping("getAll")
    public List<JiBing2> getAll(){
        log.info("jibing"+jiBingService.getAll());
        List<JiBing> list=jiBingService.getAll();
       return jiBingService.getAll2(list);
    }
    @PostMapping("update")
    public JiBing2 update(@RequestBody JiBing2 jiBing2){
       return jiBingService.update(jiBing2);
    }
    @PostMapping("delete")
    public void delete(@RequestBody Integer bbid){
        jiBingService.delete(bbid);
    }

    @GetMapping("/findByPage")
    public Page<JiBing2> findByPage(@RequestParam(value = "pageCode" ,defaultValue = "0")int pageCode,
                                 @RequestParam(value = "pageSize" ,defaultValue = "3")int pageSize) {
        log.info("疾病页码"+pageCode);
        log.info("疾病条数"+pageSize);
        Page<JiBing2> jiBing2Page= jiBingService.findByPage(pageCode,pageSize);
//        log.info("jibing2Page"+jiBing2Page);
//        log.info("总数"+jiBing2Page.getTotalElements());
        return jiBing2Page;
    }
    @GetMapping("/getTotalNum")
    public int getTotalNum(){
       return jiBingService.getNum();
    }
    @PostMapping("getOne")
    public JiBing2 getOne(@RequestBody int bbid){
       return jiBingService.getOneById(bbid);
    }
    @PostMapping("search")
    public List<JiBing2> search(@RequestBody String bname){
        List<JiBing> list=jiBingService.getAll();
        List<JiBing2> list1=jiBingService.getAll2(list);
        List<JiBing2> list2= jiBingService.searchByName(list1,bname);
        return list2;
    }
}
